<template>
    <div class="app-container">
        <el-carousel indicator-position="outside">
            <el-carousel-item v-for="item in imgs" :key="item.url">
                <img :src="item.url"/>
            </el-carousel-item>
        </el-carousel>
        <el-row :gutter="20">
            <el-col :span="12">
                <h2>健身计划</h2>
                <el-collapse style="width: 100%;">
                    <el-collapse-item v-for ="(item,index) in scheduleList  " :key='index'  >
                        <template slot="title">
                            <span style="float:left;font-weight:bold;font-size:14px;color:#2C8DF4;">{{item.scheduleName}}</span>
                        </template>
                        <!-- <div>内容类型：{{ dict.type.sys_knowledge[item.knowledgeContentType] }}</div> -->
                        <div>内容：{{delTag(item.scheduleFitnessContent)}} </div>
                    </el-collapse-item>
                </el-collapse>
            </el-col>
            <el-col :span="12">
              <h2>健身知识</h2>
                <el-collapse style="width: 100%;">
                    <el-collapse-item v-for ="(item,index) in fitnessknowledgeList  " :key='index'  >
                        <template slot="title">
                            <span style="float:left;font-weight:bold;font-size:14px;color:#2C8DF4;">{{item.knowledgeTitle}}</span>
                        </template>
                        <!-- <div>内容类型：{{ dict.type.sys_knowledge[item.knowledgeContentType] }}</div> -->
                        <div>描述：{{item.knowledgeDescription}}</div>
                        <div>内容：{{item.knowledgeContent}} </div>
                    </el-collapse-item>
                </el-collapse>
            </el-col>
        </el-row>
        
    </div>
</template>
<script>

import { listFitnessknowledge, getFitnessknowledge, delFitnessknowledge, addFitnessknowledge, updateFitnessknowledge } from "@/api/system/fitnessknowledge";
import { listSchedule, getSchedule, delSchedule, addSchedule, updateSchedule } from "@/api/system/schedule";

export default{
    name: "Fitnessknowledge",
    dicts: ['sys_knowledge','sys_difficulty', 'sys_body_part', 'sys_equipment'],
    name: "Schedule",
    data: function () {
        return {
            platform: 'pc',
            imgs: [
                { url:require('../assets/luboPic/lb1.png')},
                { url:require('../assets/luboPic/lb2.jpg')},
                { url:require('../assets/luboPic/lb3.png')},
                { url:require('../assets/luboPic/lb4.png')},
                { url:require('../assets/luboPic/lb5.jpg')},
            ],
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 健身知识信息表格数据
            fitnessknowledgeList: [],
             // 健身计划推荐表格数据
            scheduleList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                knowledgeTitle: null,
                knowledgeContentType: null,
            },
            // 表单参数
            form: {},
        }
    },
    created() {
        this.getList();
        this.getScheduleList();
    },
    methods: {
    /** 查询健身计划信息列表 */
    getScheduleList() {
      this.loading = true;
      listSchedule(this.queryParams).then(response => {
        this.scheduleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询健身知识信息列表 */
    getList() {
      this.loading = true;
      listFitnessknowledge(this.queryParams).then(response => {
        this.fitnessknowledgeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //移除HTML标签
    delTag(str){
      return str.replace(/<[^>]+>/g,"");
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        knowledgeId: null,
        knowledgeTitle: null,
        knowledgeContentType: null,
        knowledgeDescription: null,
        knowledgeContent: null,
        scheduleId: null,
        scheduleName: null,
        scheduleFitnessEquipment: null,
        scheduleFitnessPart: null,
        scheduleFitnessTime: null,
        scheduleFitnessDifficulty: null,
        scheduleFitnessContent: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加健身知识信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const knowledgeId = row.knowledgeId || this.ids
      getFitnessknowledge(knowledgeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改健身知识信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.knowledgeId != null) {
            updateFitnessknowledge(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFitnessknowledge(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const knowledgeIds = row.knowledgeId || this.ids;
      this.$modal.confirm('是否确认删除健身知识信息编号为"' + knowledgeIds + '"的数据项？').then(function() {
        return delFitnessknowledge(knowledgeIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/fitnessknowledge/export', {
        ...this.queryParams
      }, `fitnessknowledge_${new Date().getTime()}.xlsx`)
    }
  }
}

</script>
